<?php
/**
 * @author Nguyễn Sơn Tùng <sontung.x305@gmail.com> <Y!M: terminator_nst> <Skype : joker.x305>
 * @version: 1.0
 * @copyright fteam.vn
 * Date: 20/02/2013
 * Time: 15:08
 */
class fileOnServer extends CValidator {
    public $mime = array();
    protected function validateAttribute($object,$attribute) {
        $value = $object->$attribute;
        if($value != '' && $value != null) {
            $path = $_SERVER['DOCUMENT_ROOT'].$value;
            $file = cmsFile()->set($path);
            if($file->isfile) {
                if($this->mime) {
                   if(!in_array($file->mimeType,$this->mime)) {
                       $this->addError($object,$attribute,t('File was not accepted by the Server','Validator'));
                   }
                }
            } else {
                $this->addError($object,$attribute,t('File not found','Validator'));
            }
        }
    }
}